/*
 * Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
 *
 * Licensed under the Mulan PSL v2.
 * You can use this file according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of the License at
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
 * FOR MORE DETAILS.
 */

#pragma once
#include <set>

#include "Utility/Configuration/SGParameter.h"

#include "DataStructure/Common/Id.h"
#include "DataStructure/Input/Solver/AnaysisTypes.h"

#include "DBManager/Common/DBManagerExport.h"
#include "DBManager/DBServiceFactory.h"
SG_DBMANAGER_NAMESPACE_OPEN

/*

SOL 105
DISP (TM=1.-3,PRINT,PLOT,SORT2) = 20
SUBCASE 10
LOAD = 10
SUBCASE 25
METHOD = 10
以上述BDF为例，介绍SUBCASE的参数解析形式：
1：SUBCASE的形式为 SubcaseID ：{SingleSubcaseParameter}，解析后将存在key为"10","25"两个Parameter
2：SingleSubcaseParameter的形式为 CaseKey:{CaseParameter}, subcase 10的CaseKey包含为"ANALYSIS"，"SUBCASE"，"DISPLACEMENT"，"LOAD"。
3：CaseKey一定包含"ANALYSIS"与"SUBCASE"
4：DISP (TM=1.-3,PRINT,PLOT,SORT2) = 20为例介绍CaseParameter。
  解析后为
     "DISPLACEMENT": {
         "MAIN_KEY": "20",
         "MAP_KEY": {
             "TM": "1.-3"
         },
         "VECTOR_KEY": [
             "PRINT",
             "PLOT",
             "SORT2"
         ]
     },
4.1：每个CaseParameter包含的key为"MAIN_KEY"，"MAP_KEY"，"VECTOR_KEY"。其中MAIN_KEY一定存在。
4.2：VECTOR_KEY对应的为字符串数组
4.3：MAP_KEY为mapParameter，mapParameter即为Key-Value。

整个解析后的Parameter如下
{
 "10": {
     "ANALYSIS": {
         "MAIN_KEY": "STATICS"
     },
     "DISPLACEMENT": {
         "MAIN_KEY": "20",
         "MAP_KEY": {
             "TM": "1.-3"
         },
         "VECTOR_KEY": [
             "PRINT",
             "PLOT",
             "SORT2"
         ]
     },
     "LOAD": {
         "MAIN_KEY": "10"
     },
     "SUBCASE": {
         "MAIN_KEY": "10"
     },
 },
 "25": {
     "ANALYSIS": {
         "MAIN_KEY": "BUCK"
     },
     "DISPLACEMENT": {
         "MAIN_KEY": "20",
         "MAP_KEY": {
             "TM": "1.-3"
         },
         "VECTOR_KEY": [
             "PRINT",
             "PLOT",
             "SORT2"
         ]
     },
     "DLOAD": {
         "MAIN_KEY": "2"
     },
     "METHOD": {
         "MAIN_KEY": "10"
     },
     "SPC": {
         "MAIN_KEY": "10"
     },
     "STATSUB": "10",
     "SUBCASE": {
         "MAIN_KEY": "25"
     },
 }
}
*/

class DBManager_DECLSPEC ISubcaseService
{
  public:
    virtual ~ISubcaseService () {};

    /// @brief 初始化仓库，每次初始化都会被覆盖
    /// @param entity
    virtual void Initial (SG::Utility::SGParameter entity) = 0;

    /// @brief 返回整个subcse的信息
    virtual SG::Utility::SGParameter GetSubcase () = 0;

    /// @brief 获取所有的SubCase ID
    virtual std::vector<SG::DataStructure::Common::Id> GetAllSubcaseID () = 0;

    /// @brief 获取某一个SubCase
    /// @param subcaseId
    virtual SG::Utility::SGParameter FindSubCase (SG::DataStructure::Common::Id subcaseId) = 0;

    /// @brief 获取所有的SubCase ID
    /// @param subcaseId subcaseId的vector
    virtual std::set<SG::DataStructure::Common::Id> GetLoadsetIds (const std::vector<SG::DataStructure::Common::Id>& subcaseId) = 0;

    /// @brief 复制数据到指定数据库
    virtual SG::DataStructure::Common::Status CopyData (DBServiceFactory* const dest) = 0;

    /// @brief 获取分析类型
    /// @details 根据subcaseId获取分析类型
    /// @details 如果subcaseId不存在，则返回SOL_UNKNOWN
    /// @details 如果subcaseId存在但没有分析类型，则返回SOL_UNKNOWN
    /// @param subcaseId
    /// @return
    virtual SG::DataStructure::FEM::SOLType GetSOLType (SG::DataStructure::Common::Id subcaseId) = 0;
};

template <>
std::shared_ptr<ISubcaseService> DBManager_DECLSPEC DBServiceFactory::get ();

SG_DBMANAGER_NAMESPACE_CLOSE
